﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<!--/* 加载IE8兼容性片段 */-->
<head>
    <title>数据源管理</title>
    <!--/* 加载全局样式 */-->
    <th:block th:replace="common/thinDecorator::globalStyle"></th:block>
    <!--/* 加载全局主题样式 */-->
    <th:block th:replace="common/thinDecorator::globalThemeStyle"></th:block>
    <!--/* 加载全局布局样式 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutStyle"></th:block>
</head>

<body class="page-content-white page-container-bg-solid" style="overflow-x: hidden;">
<div class="page-wrapper">
    <!-- BEGIN CONTAINER -->
    <div class="page-container">
        <!-- BEGIN CONTENT -->
        <div class="page-content-wrapper">
            <!-- BEGIN CONTENT BODY -->
            <div class="page-content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="portlet light" style="margin-bottom: 0px;">
                            <div class="portlet-title">
                                <button type="button" class="btn btn-success " onclick="javascript:App.search();">
                                    搜索
                                </button>
                                <button type="button" class="btn btn-success" style="margin-left: 5px"
                                        onclick="javascript:App.reset();">
                                    重置
                                </button>
                                <button type="button" class="btn btn-danger" style="margin-left: 5px"
                                        onclick="javascript:dataList.selectList(1,'showOne');" id="showOne">
                                    待审批
                                </button>
                                <button type="button" class="btn btn-default" style="margin-left: 5px"
                                        onclick="javascript:dataList.selectList(2,'showTwo');" id="showTwo">
                                    审批通过
                                </button>
                                <button type="button" class="btn btn-default" style="margin-left: 5px"
                                        onclick="javascript:dataList.selectList(3,'showThree');" id="showThree">
                                    审批驳回
                                </button>
                                <button type="button" class="btn btn-info" style="margin-left: 5px"
                                        onclick="javascript:dataList.doApproved('adopt');">
                                    <i class="layui-icon layui-icon-face-smile"></i>   审批通过
                                </button>
                                <button type="button" class="btn btn-warning" style="margin-left: 5px"
                                        onclick="javascript:dataList.doApproved('reject');">
                                    <i class="layui-icon  layui-icon-face-cry"></i>审批驳回
                                </button>
                            </div>
                            <div class="portlet-body">
                                <table id="table" style="width:100%;"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- END CONTENT BODY -->
        </div>
        <!-- END CONTENT -->
    </div>
</div>
<div id="scripts">
    <!--/* 加载IE8兼容性脚本 */-->
    <th:block th:replace="common/thinDecorator::IE8FixScripts"/>
    <!--/* 加载核心插件脚本 */-->
    <th:block th:replace="common/thinDecorator::corePluginsScripts"/>
    <!--/* 加载全局主题脚本 */-->
    <th:block th:replace="common/thinDecorator::globalThemeScripts"/>
    <!--/* 加载全局布局脚本 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutScripts"/>
    <th:block th:replace="common/thinDecorator::globalsetupScripts"/>
    <!--Axios请求-->
    <script th:src="@{/Vue/axios.min.js}" type="text/javascript" charset="utf-8"></script>
    <script th:inline="javascript">
        layui.use(['upload', 'layer'], function () {
            var upload = layui.upload;
            var layer = layui.layer;
            // 附件上传执行实例--单文件
            var uploadInst = upload.render({
                elem: '#fileUpload' //绑定元素
                , url: '/qa/excelSaveDb' //上传接口
                , multiple: false
                , exts: 'xls|xlsx'
                , number: 1
                , accept: 'file' // 接受所有类型文件
                , done: function (res) {
                    //每个文件提交一次触发一次。“成功的回调”
                    layer.msg(res.msg, {icon: 1, time: 1000});
                    $("#table").datagrid("reload");
                }, error: function (err) {
                    //请求异常回调
                    console.log(err)
                }
            });
        });
        $(function () {
            dataList.init();
        });
        var thatFBZT = "发布中";
        var dataList = {
            easyuiTableInput: {},//记录查询框输入值
            //初始化
            init: function () {
                this.easyuiTableInput = localStorageManage.get("table", "searchForm");
                if (!this.easyuiTableInput) {
                    this.easyuiTableInput = {
                        searchData: {},
                        queryParams: {},
                    };
                } else {
                    //写form表单查询
                }
                var height = App.countHeight("table");
                console.log("height is " + height)
                this.createDataGrid();
            },
            doApproved:function (thatStatus) {
                // 选择数据
                let rows = $("#table").datagrid("getSelections");
                if (rows.length < 1) {
                    layer.msg("请至少选择一行数据进行审批", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                // 如果是驳回需要填原因
                let rejectMsg = '';
                let urlPost = "/qa/approved/modifyStatus?operation="+thatStatus;
                if (thatStatus === 'reject'){
                    rejectMsg = '请输入驳回原因';
                }else {
                    rejectMsg = '请输入同意描述';
                }
                layer.prompt({
                    title: '提示：'+rejectMsg,
                    formType: 2,
                    btn:['确定','取消'],
                    area:['300px','150px']
                },function(text, index, elem){
                    rejectMsg = text;
                    urlPost = urlPost+"&thatMsg="+rejectMsg;
                    // 发送数据审批
                    axios.post(urlPost, JSON.stringify(rows), {
                        headers: {
                            'Content-Type': 'application/json'
                        }
                    }).then(resp => {
                        if (resp.data.code == 200) {
                            layer.msg(resp.data.msg, {icon: 1, time: 1000, shift: 6}, function () {
                                $("#table").datagrid("reload");
                            });
                        } else {
                            layer.msg(resp.data.msg, {icon: 2, time: 1000, shift: 6});
                        }

                    }).catch(error => {
                        console.log(error)
                    });
                    layer.close(index);
                });
            },
            selectList: function (num,thatBtnId) {
                if (num === 1) {
                    thatFBZT='发布中';
                    document.getElementById("showTwo").setAttribute("class", "btn btn-default");
                    document.getElementById("showThree").setAttribute("class", "btn btn-default");
                } else if (num === 2) {
                    thatFBZT='已发布';
                    document.getElementById("showOne").setAttribute("class", "btn btn-default");
                    document.getElementById("showThree").setAttribute("class", "btn btn-default");
                } else {
                    thatFBZT='已驳回';
                    document.getElementById("showOne").setAttribute("class", "btn btn-default");
                    document.getElementById("showTwo").setAttribute("class", "btn btn-default");
                }
                document.getElementById(thatBtnId).setAttribute("class", "btn btn-danger");
                $('#table').datagrid('options').url = "/qa/approved/datagrid?thatFbzt=" + thatFBZT;
                $("#table").datagrid("reload");
            },
            //创建datagrid
            createDataGrid: function () {
                $("#table").datagrid({
                    url: "/qa/approved/datagrid?thatFbzt=" + thatFBZT,
                    height: App.getPortletInnerHeight(),
                    queryParams: this.easyuiTableInput.queryParams,
                    frozenColumns: [
                        [
                            {field: 'checkbox', checkbox: true, align: "center", width: 35,},
                            {
                                field: 'number',
                                title: '序号',
                                align: "center",
                                width: 35,
                                formatter: function (data, row, index) {
                                    return index + 1;
                                }
                            },
                        ]
                    ],
                    columns: [
                        [

                            {
                                "field": "cnName", title: "数据质量名称", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "syfw", title: "适用范围", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "sjzllx", title: "数据质量类型", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "createUser", title: "提交人", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "createTime", title: "申请审批时间", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "ckwx", title: "参考文献", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "sjzlbzml", title: "所属质量标准分类", width: 120, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "fbzt", title: "发布状态", width: 100, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            }
                        ]
                    ],
                    fitColumns: false,//自适应
                    remoteFilter: true,
                    remoteSort: true,
                    clientPaging: false,
                    singleSelect: false,//单选
                    checkOnSelect: true,
                    striped: true, //表格设置为条纹
                    emptyMsg: "表中数据为空",
                    pagination: true,//分页
                    pagePosition: "bottom",
                    pageList: [20, 50, 100],
                    pageSize: 20,
                    automaticPolling: false,
                    onDblClickRow: function (rowIndex, row) {
                    }
                });
                this.createFilter();
            },
            //模糊查询
            createFilter: function () {
                $('#table').datagrid('enableFilter', [
                    {"field": "number", type: 'label',},
                    {
                        "field": "cnName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.cnName,
                        }
                    },
                    {
                        "field": "syfw", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.syfw,
                        }
                    },
                    {
                        "field": "sjzllx", type: 'combobox', options: {
                            valueField: 'code',
                            textField: 'name',
                            editable: false,
                            data: [{code: '数据模型标准', name: '数据模型标准'}, {
                                code: '数据编码标准',
                                name: '数据编码标准'
                            }, {code: '主数据接口标准', name: '主数据接口标准'}],
                            value: dataList.easyuiTableInput.searchData.sjzllx,
                        }
                    },
                    {
                        "field": "createUser", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.createUser,
                        }
                    },
                    {
                        "field": "createTime", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.createTime,
                        }
                    },
                    {
                        "field": "ckwx", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.ckwx,
                        }
                    },
                    {
                        "field": "sjzlbzml", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.sjzlbzml,
                        }
                    },
                    {
                        "field": "fbzt", type: 'combobox', options: {
                            valueField: 'code',
                            textField: 'name',
                            editable: false,
                            data: [{code: '已发布', name: '已发布'}, {code: '未发布', name: '未发布'}, {
                                code: '发布中',
                                name: '发布中'
                            },{code: '已驳回', name: '已驳回'}],
                            value: dataList.easyuiTableInput.searchData.fbzt,
                        }
                    },
                ]);
                var searchBtn = '<a class="table-action" style="margin-left: 1px" onclick="App.search()">查询</a>';
                $('.datagrid-filter-row td[field="number"]').html(searchBtn);
            },
            edit: function () {
                var row = $("#table").datagrid("getSelected");
                if (0 !== row.stateId) {
                    layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
                    return false;
                }
                layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
            },
            back: function () {
                layer.msg("该数据无法编辑", {icon: 2, time: 1000, shift: 6});
            },
        };
    </script>
</div>
<!-- END CONTAINER -->
</body>

</html>